package extensions.games;

import com.jme3.renderer.RenderManager;

import extensions.romario.packet.AbstractPacket;
import extensions.romario.server.Lobby;

public abstract class AbstractGame {

	public enum GameStatus
	{
		Started,
		Finished	//Game wants to return to lobby
	}
	
	private GameStatus _gameStatus = GameStatus.Started;
	private String _name = "None";
	private int[] _scores;
	
	public AbstractGame(String name) {
		_name = name;
	}
	
	/**
	 * Inits the game with players in lobby.
	 * @param lobby
	 */
	public void init(Lobby lobby)
	{
		_scores = new int[lobby.getPlayersCount()];
		initialize();
	}

	/*
	 * private Map<Integer, AbstractPacket> _packets = new HashMap<Integer,
	 * AbstractPacket>();
	 * 
	 * protected void registerClientPacket(int id, AbstractPacket packet) { }
	 */

	public void onPacketReceived(int playerId, AbstractPacket packet) {
	}

	protected abstract void initialize();

	public abstract void render(RenderManager render);

	public abstract void update(float dt);

	public String getName() {
		return _name;
	}
	
	protected void setStatus(GameStatus status)
	{
		_gameStatus = status;
	}
	
	public GameStatus getStatus()
	{
		return _gameStatus;
	}
	
	/**
	 * Scores returned by the game on finish.
	 * @return
	 */
	public int[] getScores()
	{
		return _scores;
	}

	@Override
	public String toString() {
		return _name;
	}

}
